const { executeInEditMode, ccclass, property } = cc._decorator;

@ccclass
@executeInEditMode
export default class CharacterPart extends cc.Component {
    @property
    z = 0;
    @property
    partName = "";

    @property({
        serializable: true
    })
    _color: cc.Color = cc.color();
    @property
    get color() {
        return this._color;
    }
    set color(val) {
        this._color = val;
        this.refreshColor();
    }
    @property({
        serializable: true
    })
    _shadow = 0;
    @property
    get shadow() {
        return this._shadow;
    }
    set shadow(val) {
        this._shadow = val;
        this.refreshColor();
    }
    refreshColor() {
        let col = this._color.clone();
        if (this._shadow > 0) {
            // {h: 0.1533864541832669, s: 0.9843137254901961, v: 1}
            // Hue: 色环（0-360）， S饱和度， V明度
            let hsv = col.toHSV();
            hsv.v *= this._shadow;
            col.fromHSV(hsv.h, hsv.s, hsv.v);
        }
        this.node.color = col;
    }
    init() {
        this.node.name = this.partName;
        // if( !CC_EDITOR ){ 
        //     this.node.zIndex = this.z;
        // }
    }
};